package com.zhangwei.liwushuo.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.zhangwei.liwushuo.R;
import com.zhangwei.liwushuo.bean.ChannelsEntity;

import java.util.List;

/**
 * @说 明：
 * @项目名称：LiWuShuo
 * @包 名： com.zhangwei.liwushuo.adapter
 * @类 名： CategoryGvAdaPTER
 * @创 建人： zhangwei
 * @创建时间：2015-08-21 17:36
 * @版 本：v1.0
 * @修 改人：
 * @修改时间：
 * @修改备注：
 */
public class CategoryGvAdapter extends BaseAdapter {


    private List<ChannelsEntity> list;

    LayoutInflater inflater;

    public CategoryGvAdapter(List<ChannelsEntity> list, LayoutInflater inflater, Context context) {
        this.list = list;
        this.inflater = inflater;

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ChannelsEntity entity = list.get(position);
        ViewHolder cvh;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_cate_child_layout, parent, false);
            cvh = new ViewHolder(convertView);
            convertView.setTag(cvh);
        } else {
            cvh = (ViewHolder) convertView.getTag();
        }
        cvh.nameTv.setText(entity.getName());
        cvh.img.setImageURI(Uri.parse(entity.getIcon_url()));
        return convertView;
    }

    private static class ViewHolder {
        TextView nameTv;
        SimpleDraweeView img;

        public ViewHolder(View convertView) {
            nameTv = (TextView) convertView.findViewById(R.id.item_cate_child_name);
            img = (SimpleDraweeView) convertView.findViewById(R.id.item_cate_child_img);

        }
    }


}
